home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / TransferProvider / ProviderFactory.c next >
Encoding:
Text File  |  2000-09-28  |  2.6 KB  |  90 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ProviderFactory.c
  3.  
  4.     Contains:    Sample that shows how to use OTTransferProviderOwnership.
  5.  
  6.     Written by: Quinn "The Eskimo!"    
  7.  
  8.     Copyright:    Copyright © 1997-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/23/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. ////////////////////////////////////////////////////////////
  24. // Pick up general Open Transport stuff.
  25.  
  26. #include <OpenTransport.h>
  27.  
  28. ////////////////////////////////////////////////////////////
  29. // Pick up OT debugging macros.
  30.  
  31. #include <OTDebug.h>
  32.  
  33. ////////////////////////////////////////////////////////////
  34. // Get our own prototype.
  35.  
  36. #include "ProviderFactory.h"
  37.  
  38. ////////////////////////////////////////////////////////////
  39. // OTDebugStr is not defined in any of the interfaces,
  40. // but it is in the libraries.
  41.  
  42. extern void OTDebugStr(char *str);
  43.  
  44. ////////////////////////////////////////////////////////////
  45.  
  46. static Boolean gOTInited = false;
  47.  
  48. ////////////////////////////////////////////////////////////
  49. // Provider factory routines.
  50.  
  51. extern OSStatus FactoryCreateEndpoint(EndpointRef *ref, OTClient *currentOwner)
  52.     // See comment in interface part.
  53.     // In this example, we arbitrarily create an ADSP endpoint.  This
  54.     // technique works for all types of endpoints.
  55. {
  56.     OSStatus err;
  57.     
  58.     OTAssert("FactoryCreateEndpoint: Parameter error", ref != nil);
  59.     OTAssert("FactoryCreateEndpoint: Parameter error", currentOwner != nil);
  60.     OTAssert("FactoryCreateEndpoint: Called but we weren't successfully inited.", gOTInited);
  61.  
  62.     *currentOwner = OTWhoAmI();
  63.     *ref = OTOpenEndpoint(OTCreateConfiguration("adsp"), 0, nil, &err);
  64.  
  65.     return err;
  66. }
  67.  
  68. ////////////////////////////////////////////////////////////
  69. // Initialisation and termination routines.
  70.  
  71. extern OSStatus InitProviderFactory(void)
  72.     // See comment in interface part.
  73. {
  74.     OSStatus err;
  75.     
  76.     err = InitOpenTransport();
  77.     gOTInited = (err == noErr);
  78.     
  79.     return err;
  80. }
  81.  
  82. extern void CloseProviderFactory(void)
  83.     // See comment in interface part.
  84. {
  85.     OTAssert("CloseProviderFactory: Called but we weren't successfully inited.", gOTInited);
  86.     if (gOTInited) {
  87.         CloseOpenTransport();
  88.     }
  89. }
  90.